package com.ego.admin.controller;

import com.ego.admin.po.SysOperationLog;
import com.ego.admin.service.SysOperationLogService;
import com.ego.admin.vo.SysOperationSearchVo;
import com.ego.common.annotation.ControllerEndpoint;
import com.ego.common.util.Result;
import com.ego.common.vo.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: ego
 * @description: 系统操作日志控制器
 * @author: KamTang
 * @create: 2023-05-02 10:12
 **/
@RestController
@RequestMapping("/sys/log")
public class SysOperationLogController {
    @Autowired
    private SysOperationLogService logService;

    /**
     * 搜索
     */
    @PostMapping("/search")
    public Result search(@RequestBody SysOperationSearchVo searchVo) {
        PageVo<SysOperationLog> page = logService.search(searchVo);
        return Result.ok().put("page", page);
    }

    /**
     * 删除
     */
    @ControllerEndpoint(exceptionMessage = "操作日志删除失败", operation = "删除操作日志")
    @PostMapping("/delete")
    public Result delete(@RequestBody Long[] ids) {
        try {
            logService.deleteBatch(ids);
        } catch (Exception e) {
            return Result.error();
        }
        return Result.ok();
    }
}
